welcome back to another lesson in this tutorial we are going to learn how to use pandas built in method to do the sampling for us previously we have learned in order to reduce the workload and in order to make analysis more meaningful sometimes we need to drop the attributes which is dimension elimination sometimes we want to reduce the dataset in terms of the records in terms of the rows and this is the sampling work basically we are going to select certain rows or we are going to play with certain rows to make our representation of the dataset that is meaningful and useful in terms of giveing us a feeling of what the entire dataset might be so let's get into the setup basically we will need Numpy as np we will need pandas as pd we have done it many times for the dataset we are still going to use the built in dataset which is california housing train you can access dataset by clicking the left panel files and then drop the menu of the sample data down and select this california_housing_trend.CSV click the 3 dots here copy the path and paste it into the read_csv() function okay now you have the data frame read in as df let's just print out your data frame info basically we have 9 attributes and we worked on attributes elimination before and we have 17 thousands of records this is the object we are going to play with today let's first look at how to do sampling by numbers this one is the most straightforward one basically you call from df you call the sample function and then you fill this function with any number you want and then you can feed it with 5 like we are having here and you may also feed it with 500 or 10,000 or any number you think that is appropriate for you to do a sampling for your test of the dataset and you can see that the 5 numbers is actually draw randomly from all these 17,000 of records so basically every time you draw the 5 sample it might be a little bit different another way to draw the sampling is rather than give the particular absolute number you can do the sampling by percentage in this way you are going to fit with another argument which is fraction this fraction basically represents the percentage you want from the dataset for example here we have 17 thousands of records if we just want to have 1/1000 of them, which are 17 records then we can call fraction equal to 0.001 which will give you 0.1% so this will be the 17 records we can have by this random call and the random sample is drawn from that many records and also you can see every time you run this sample this will give you some different records okay so that will be the most staright forward that is by number how many you want or by percentage how much percentage you want as a sample the other one I would like to address is when we do the sampling for example you can actually choose what is the range you want for your sample to draw from and if you do not specify anything like the loc, locate and the index label basically you are going to draw the sample from every record in a data frame if you specify any sub rows or sub dataframe by choosing either by index of the rows or by index of the column in etc then you are going to draw that sample from the resulted data frame so that will be something you want to make customization as well the other one I purposely showing here and if we are going to join a sample from the first 10 rows and the fraction is 0.9 basically we need 9 rows as you can see here we are basically only remove one record from it in this case I believe it is recorded number 6 but when you run a program you may have a little bit different result because a normal sample method no matter it is by fraction by number they are all using no replacement strategy when you learn ensemble when you learn bagging and the boosting etc you are going to learn this fundamental difference between replacement and the no replacement strategy for sampling basically if you are doing a sampling without replacement if you draw one record out then you are not going to put this record back into the pool in other words once you use this record this record will be in another bin and this record will not be in the pool anymore however with replacement simply as we can see here when you specify you need a number as 15 when you need a replacement is true basically that means that once you draw this record out you are going to place it back into the pool and you will have the chance to draw it out again in other words is that for these 10 records you can actually make a sample that is even more than these 10 records in this case we have 15 of our final output it's because you can see the 1 is repeated for 5 times just randomly and the 3 has repeated for 2 times and the 4 has another 4 times and actually we cannot find  8 or 7, etc so this with replacement equal to true can enable you to play with the record rather than just select them but you can also select them multiple times that will be the sampling method and as you can see sampling method is very straightforward and simple the only difference you may need to pay attention is you need to call the appropriate argument either by number or by fraction and you have to pay attention to the replacement is true or false by default it will be false but sometimes you need it to be true just in case